﻿using System;
using System.Collections.Generic;
using System.Text;
using StarBotDotNet;

namespace StarBotDotNet
{
    public class MiningParty:UnitParty
    {
        Dictionary<StarBotDotNet.UnitType, int> requiredUnits;
        public MiningParty(ProxyBot bot)
        {
            requiredUnits = new Dictionary<UnitType, int>();
            requiredUnits.Add(bot.GetCurrentPlayerWorkerType(), 12);
        }

        public override void ExecuteTactics(StarBotDotNet.ProxyBot bot, UnitDictionary currentUnits, int currentTime)
        {
            foreach (UnitData unit in this.GetAllUnits())
            {

                // make idle works mine				
                if (unit.OwnedByPlayer && unit.IsIdle && unit.IsWorker)
                {


                        int closestID = -1;
                        //UPGRADE_TODO: The equivalent in .NET for field 'java.lang.Double.MAX_VALUE' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        double closest = System.Double.MaxValue;

                        foreach (Unit patch in bot.Units)
                        {

                            if (patch.Type.Id == (int)Constants.UnitTypes.Resource_Mineral_Field)
                            {

                                double distance = (0.5 + SupportClass.Random.NextDouble()) * unit.Unit.distance(patch);
                                if (distance < closest)
                                {
                                    closest = distance;
                                    closestID = patch.ID;
                                }
                            }
                        }

                        if (closestID != -1)
                        {
                            Utilities.WriteColorLine(ConsoleColor.Cyan, "Right on patch: " + unit.Unit.ID + " " + closestID);
                            bot.rightClick(unit.Unit.ID, closestID);
                        }
                    
                }
            }
        }



        public override int Priority
        {
            get 
            {
                return 0;
            
            }
        }


        public override Dictionary<StarBotDotNet.UnitType, int> RequiredUnits
        {
            get
            {
                return requiredUnits;
            }
        }

        protected override bool IsUnused(UnitData data)
        {
            return data.IsIdle;
        }
    }
}
